package _interview150;

/**
 * 209. 长度最小的子数组
 */
public class No209 {
    public int minSubArrayLen(int target, int[] nums) {
        int start = 0, end = -1;
        int curSum = 0;
        int ans = Integer.MAX_VALUE;
        while (end < nums.length - 1) {
            curSum += nums[++end];
            while (curSum >= target) {
                ans = Math.min(end - start + 1, ans);
                curSum -= nums[start++];
            }
        }
        return ans == Integer.MAX_VALUE ? 0 : ans;
    }
}
